package com.hjh.mp.generator.config;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.io.Resources;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Data
public class MpGeneratorConfig {


    private Properties properties;

    public void load() {
        String resource = "mp_generator.properties";
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream(resource);
            properties = new Properties();
            properties.load(is);
            init();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
    }

    //数据库配置
    private String dbType;
    private String url;
    private String userName;
    private String passWord;
    private String driverName;

    private void init() {
          dbType = getProperty("mp.datasource.dbType");
        System.out.println("=========>>mp.datasource.dbType:" + dbType);

          url = getProperty("mp.datasource.url");
        System.out.println("=========>>mp.datasource.url:" + url);


          userName = getProperty("mp.datasource.userName");
        System.out.println("=========>>mp.datasource.userName:" + userName);


          passWord = getProperty("mp.datasource.passWord");
        System.out.println("=========>>mp.datasource.passWord:" + passWord);


          driverName = getProperty("mp.datasource.driverName");
        System.out.println("=========>>mp.datasource.driverName:" + driverName);

    }

    private String getProperty(String key) {
        return StringUtils.trimToEmpty(properties.getProperty(key));
    }
}
